package org.jiajie.coffeecodes.demo.jvm._native;

import org.jiajie.coffeecodes.demo.jvm._native.java.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jie
 */
public class Registry {

    private static Map<String, NativeMethod> registry = new HashMap<>();

    /**
     * 初始化本地方法
     */
    public static void initNative(){
        new _Class();
        new _Double();
        new _Float();
        new _Object();
        new _String();
        new _System();
    }

    public static void register(String className, String methodName, String methodDescriptor, NativeMethod method){
        String key = className + "~" + methodName + "~" + methodDescriptor;
        registry.put(key, method);
    }

    public static NativeMethod findNativeMethod(String className, String methodName, String methodDescriptor){
        String key = className + "~" + methodName + "~" + methodDescriptor;
        return registry.get(key);
    }
}
